﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Data;

namespace CMD.BAL.SOL
{
    [DataContractAttribute]
    public class DocumentosWeb
    {
        [DataMemberAttribute(EmitDefaultValue = false)]
        public List<DocumentosWeb> docs;
        [DataMemberAttribute(EmitDefaultValue = false)]
        public string unidDocs;
        [DataMemberAttribute(EmitDefaultValue = false)]
        public string doctos_unidDoctos;
        [DataMemberAttribute(EmitDefaultValue = false)]
        public string doctos_unidDoc;
        [DataMemberAttribute(EmitDefaultValue = false)]
        public string doctos_orgFileName;
        
        public static List<DocumentosWeb> GetDataListDocuments(string idSolicitud)
        {
            try
            {
                DataTable dt = CMD_WEB.DAL.SrvDB.ExecuteQuery("exec SP_CMD_GET_WEB_DOC'" + idSolicitud + "'");
                if (dt.Rows.Count == 0)
                {
                    return null;
                }
                else
                {
                    List<DocumentosWeb> list = dt.AsEnumerable().Select(
                        row => new DocumentosWeb
                        {
                            doctos_unidDoc = String.IsNullOrEmpty(row.Field<Int64>(0).ToString())
                            ? ""
                            : row.Field<Int64>(0).ToString(),
                            doctos_orgFileName = String.IsNullOrEmpty(row.Field<string>(1))
                            ? ""
                            : row.Field<string>(1),
                        }
                        ).ToList();
                    return list;
                }
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public static DocumentosWeb GetDataDocumets(string idSolicitud)
        {
            try
            {
                DocumentosWeb docs;
                DataTable dt = CMD_WEB.DAL.SrvDB.ExecuteQuery("exec SP_CMD_GET_WEB_DOCUMENTOS'" + idSolicitud + "'");
                if (dt.Rows.Count == 0)
                {
                    return null;
                }
                else if (idSolicitud == "")
                {
                    return null;
                }
                else
                {
                    docs = new DocumentosWeb(Convert.ToString(dt.Rows[0]["doctos_unidDoctos"]), null);
                }
                return docs;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public DocumentosWeb() 
        {
            //unidDocs = "";
            //orgFileName = "";
        }
        public DocumentosWeb(string doctos_unidDoctos, List<DocumentosWeb> docs)
        {
            this.docs = docs;
            this.doctos_unidDoctos=doctos_unidDoctos;
        }
    }
}
